{% extends 'base.html' %}
{% block title %}{{ book.title }} - 图书详情{% endblock %}
{% block content %}
    <h1>{{ book.title }}</h1>
    <p><strong>作者：</strong>{{ book.author }}</p>
    <p><strong>简介：</strong>{{ book.summary }}</p>
    <p><strong>ISBN：</strong>{{ book.isbn }}</p>
    <h2>馆藏情况</h2>
    <table>
        <tr>
            <th>版本信息</th>
            <th>到期日</th>
            <th>状态</th>
            <th>借阅者</th>
        </tr>
        {% for inst in instances %}
        <tr>
            <td>{{ inst.imprint }}</td>
            <td>{{ inst.due_back }}</td>
            <td>
                {% if inst.status == 'a' %}可借阅{% elif inst.status == 'o' %}已借出{% elif inst.status == 'm' %}维护中{% elif inst.status == 'r' %}已预订{% endif %}
            </td>
            <td>{% if inst.borrower %}{{ inst.borrower.username }}{% else %}-{% endif %}</td>
        </tr>
        {% endfor %}
    </table>
    {% if user.is_authenticated %}
        <form method="post" style="margin-top:16px;">
            {% csrf_token %}
            {% if can_borrow %}
                <button type="submit" name="action" value="borrow" class="btn">借阅</button>
            {% elif user_borrowed %}
                <button type="submit" name="action" value="return" class="btn">归还</button>
            {% endif %}
        </form>
    {% else %}
        <p>请先<a href="{% url 'login' %}">登录</a>后进行借阅操作。</p>
    {% endif %}
    <p><a href="{% url 'book-search' %}" class="btn">返回搜索</a></p>
{% endblock %} 